/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.dao;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import javax.swing.JOptionPane;

/**
 *
 * @author Cícero
 */
public class ConectaBanco {
    
    public Statement pst;
    public ResultSet rs;
    private String driver = "com.mysql.jdbc.Driver";
    private String caminho = "jdbc:mysql://localhost:3306/bancosysepi";
    private String usuario = "root";
    private String senha = "root";
    public Connection con;   
    
    public void conexao(){
	try{
            System.setProperty("jdbc.Drivers", driver);
            con = DriverManager.getConnection(caminho,usuario,senha);
              //JOptionPane.showMessageDialog(null,"Conectado com sucesso");
	} catch(SQLException ex){
	     JOptionPane.showMessageDialog(null, ex);			   
	}		   
 } 
    public void desconecta(){        
        try {
            con.close();
            //JOptionPane.showMessageDialog(null,"Desconectado com sucesso");
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(null, ex);
        }        
    }
    public void executaSQL(String SQL) {
       try{
         pst = con.createStatement(rs.TYPE_SCROLL_INSENSITIVE,rs.CONCUR_READ_ONLY);
         rs = pst.executeQuery(SQL);           
       }catch(SQLException ex){
         JOptionPane.showMessageDialog(null, ex);  
       }        
        
    }

   
}
